home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 011-020 / amok13 / rows / rows.def < prev    next >
Text File  |  1993-11-04  |  5KB  |  112 lines

  1. (**********************************************************************
  2.  
  3.     :Program.    Rows.def
  4.     :Contents.   generic data type: variable length arrays
  5.     :Author.     Nicolas Benezan [bne]
  6.     :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
  7.     :Phone.      711/333679
  8.     :Copyright.  Public Domain
  9.     :Language.   Modula-2
  10.     :Translator. M2Amiga AMSoft V3.11
  11.     :Imports.    TaskMemory [bne]
  12.     :History.    V1.0e [bne] 12.Jan.1989
  13.     :Update.     allocation procedures added [bne] 19.Jan.1989
  14.  
  15. **********************************************************************)
  16.  
  17. DEFINITION MODULE Rows;
  18.  
  19. FROM SYSTEM     IMPORT ADDRESS,BYTE;
  20.  
  21. TYPE    Row;
  22.  
  23. VAR     RowsAllocProc:PROCEDURE(VAR ADDRESS,LONGINT);
  24.         RowsDeallocProc:PROCEDURE(VAR ADDRESS);
  25. (* defaults are TaskMemory.Allocate, TaskMemory.Deallocate *)
  26.  
  27. PROCEDURE Dim(VAR row:Row;NumElements:LONGINT;
  28.               SizeOfElements:CARDINAL):BOOLEAN;
  29. (*:Input.       NumElements: number of elements in the new Row
  30.   :Input.       SizeOfElements: size in bytes of the Row's elements
  31.   :Output.      row: new initialised Row
  32.   :Result.      TRUE if there was enough free memory for the Row
  33.   :Note.        If the result is FALSE the row is still not initialized
  34.   :Semantic.    Initializes a Row and fills all elements with zero
  35.   :Note.        DO NOT perform any operation on unititialized Rows !
  36.   :Note.        before you Re-Dim() a Row you MUST Discard() it !
  37. *)
  38. PROCEDURE Discard(VAR row:Row);
  39. (*:Input.       row: any Row previously initialised
  40.   :Semantic.    Frees all memory consumed by the row
  41.   :Note.        DO NOT perform any operation on Disscard()ed Rows
  42.   :Note.        (except Dim(), of course) !
  43. *)
  44. PROCEDURE Read(row:Row;Index:LONGINT;VAR Data:ARRAY OF BYTE);
  45. (*:Input.       row: the Row Read() should refer to
  46.   :Input.       Index: number of the Element you want to Read()
  47.   :Note.        Index must be inside [0..NumElements-1]
  48.   :Output.      Data: variable where the element will be copied to
  49. *)
  50. PROCEDURE Write(row:Row;Index:LONGINT;Data:ARRAY OF BYTE);
  51. (*:Input.       row: the Row Write() should refer to
  52.   :Input.       Index: number of the Element you want to Write()
  53.   :Note.        Index must be inside [0..NumElements-1]
  54.   :Input.       Data: data that will be copied to the element
  55. *)
  56. PROCEDURE Assign(Source:Row;VAR Destination:Row):BOOLEAN;
  57. (*:Input.       Source: The (properly Dim()ed) Row you want to copy
  58.   :Input.       Destination: Row of the same NumElements+SizeOfElements
  59.   :Input.       Destination: or a Row that hasn't been Dim()ed yet
  60.   :Output.      Destination: copy of the Source, undefined if Result=FALSE
  61.   :Note.        if Destination wasn't Dim()ed it is Dim()ed automaticaly
  62.   :Result.      FALSE if an error occured, otherwise TRUE
  63.   :Semantic.    performs an assignment by copying all data
  64.   :Note.        row2:=row1 doesn't really copy
  65. *)
  66. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  67. (* the following is useful if you have Rows as "open array parameters"*)
  68. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  69. PROCEDURE High(row:Row):LONGINT;
  70. (*:Input.       row: any Row of which you don't know NumElements
  71.   :Result.      highest possible Index for the row
  72.   :Result.      if the Row is not Dim()ed High() may be undefined
  73.   :Semantic.    High() is for Rows what HIGH() is for ARRAYs
  74. *)
  75. PROCEDURE CompSize(row:Row):CARDINAL;
  76. (*:Input.       row: any Row you want to know the SizeOfElements
  77.   :Result.      Size of the Row's Elements in bytes
  78.   :Result.      if the Row is not Dim()ed CompSize() may be undefined
  79. *)
  80.  
  81. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  82. (* WARNING: Use the following procedures carefully !                    *)
  83. (*­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­*)
  84. PROCEDURE Export(row:Row;VAR Base:ADDRESS;VAR Size:LONGINT);
  85. (*:Input.       row: any (properly Dim()ed !) Row
  86.   :Output.      Base: the row's data base address in memory
  87.   :Output.      Size: the row's data size in bytes
  88.   :Semantic.    Returns the address and size of the row's data buffer
  89.   :Note.        You can use this if you want to Write() a Row to a File
  90.   :Note.        but don't make any assumptions of how to interpret the data
  91.   :Note.        Don't use Export() on Import()ed rows
  92.   :Note.        (in this case the buffer is known anyway)
  93. *)
  94. PROCEDURE Import(VAR row:Row;NumElements:LONGINT;
  95.               SizeOfElements:CARDINAL;Base:ADDRESS;Size:LONGINT);
  96. (*:Input.       row: empty Row (created by Dim(row,0,0) )
  97.   :Input.       NumElements: how many elements are in the buffer
  98.   :Input.       SizeOfElements: length of each element in bytes
  99.   :Input.       Base: the buffer base address in memory
  100.   :Input.       Size: the buffer size in bytes
  101.   :Output.      row: Row that contains the buffer's data
  102.   :Semantic.    creates a Row out of a buffer with a given Base and Size
  103.   :Note.        You can use this to Read() a Row from a file
  104.   :Note.        DO NOT re-use the buffer until Discard(row),
  105.   :Note.        data is not copied ! Neither does Import() allocate a new
  106.   :Note.        buffer nor will Discard() deallocate the buffer if the
  107.   :Note.        row was an Import()ed one !
  108.   :Note.        WARNING: if the buffer doesn't fit the specified NumElements
  109.   :Note.        and SizeOfElements the result is undefined !
  110. *)
  111. END Rows.
  112.